package com.wgl.express.service.Impl;

import com.wgl.express.entity.Station;
import com.wgl.express.entity.User;
import com.wgl.express.mapper.StationMapper;
import com.wgl.express.service.StationService;
import com.wgl.express.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;

public class StationServiceImpl implements StationService {

    @Override
    public List<Station> selectAll() {
        List<Station> station = null;
        try {
            SqlSession sqlSession = MybatisUtils.getSqlSession();
            StationMapper mapper = sqlSession.getMapper(StationMapper.class);
            station = mapper.selectAll();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return station;
    }

    @Override
    public Station selectByDeliver(int uid) {
        Station station = null;
        try {
            SqlSession sqlSession = MybatisUtils.getSqlSession();
            StationMapper mapper = sqlSession.getMapper(StationMapper.class);
            station = mapper.selectByDeliver(uid);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return station;
    }

    @Override
    public Station selectBySid() {
        return null;
    }

    @Override
    public int addOne(Station station) {
        int res = 0;
        try {
            SqlSession sqlSession = MybatisUtils.getSqlSession();
            StationMapper mapper = sqlSession.getMapper(StationMapper.class);
            res= mapper.insertOne(station);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return res;
    }

    @Override
    public int changeOne(Station station) {
        int res = 0;
        try {
            SqlSession sqlSession = MybatisUtils.getSqlSession();
            StationMapper mapper = sqlSession.getMapper(StationMapper.class);
            res= mapper.updateOne(station);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return res;
    }


    @Override
    public List<Station> getCountOfStation() {
        List<Station> stations = null;

        try {
            SqlSession sqlSession = MybatisUtils.getSqlSession();
            StationMapper mapper = sqlSession.getMapper(StationMapper.class);
            stations= mapper.listOfPost();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return stations;
    }
}
